<template>
  <div class="delivery-tasks">
    <!-- 页面标题 -->
    <div class="page-header">
      <div class="header-left">
        <h2 class="page-title">任务包管理</h2>
        <p class="page-desc">高效管理您的配送任务包，提升配送效率</p>
      </div>
      <div class="header-right">
        <el-button type="primary" @click="handleRefresh">
          <el-icon><Refresh /></el-icon>
          刷新
        </el-button>
      </div>
    </div>

    <!-- 任务包统计 -->
    <div class="task-stats">
      <div class="stat-item" :class="{ active: taskType === 'pending' }" @click="switchTaskType('pending')">
        <div class="stat-icon pending">
          <el-icon><Clock /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ stats.pending }}</div>
          <div class="stat-label">待接单</div>
        </div>
      </div>
      
      <div class="stat-item" :class="{ active: taskType === 'delivering' }" @click="switchTaskType('delivering')">
        <div class="stat-icon delivering">
          <el-icon><Van /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ stats.delivering }}</div>
          <div class="stat-label">配送中</div>
        </div>
      </div>
      
      <div class="stat-item" :class="{ active: taskType === 'completed' }" @click="switchTaskType('completed')">
        <div class="stat-icon completed">
          <el-icon><CircleCheck /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ stats.completed }}</div>
          <div class="stat-label">已完成</div>
        </div>
      </div>
      
      <div class="stat-item" :class="{ active: taskType === 'cancelled' }" @click="switchTaskType('cancelled')">
        <div class="stat-icon cancelled">
          <el-icon><Close /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ stats.cancelled }}</div>
          <div class="stat-label">已取消</div>
        </div>
      </div>
      <!-- 总数统计 -->
      <div class="stat-item sum">
        <div class="stat-icon sum">
          <el-icon><List /></el-icon>
        </div>
        <div class="stat-content">
          <div class="stat-number">{{ stats.sum }}</div>
          <div class="stat-label">任务包总数</div>
        </div>
      </div>
    </div>

    <!-- 搜索和筛选 -->
    <div class="search-section">
      <el-card class="search-card">
        <div class="search-form">
          <el-row :gutter="20">
            <el-col :span="6">
              <el-input
                v-model="searchForm.packageId"
                placeholder="任务包编号"
                clearable
                prefix-icon="Search"
              />
            </el-col>
            <el-col :span="6">
              <el-input
                v-model="searchForm.deliveryArea"
                placeholder="配送区域"
                clearable
                prefix-icon="Location"
              />
            </el-col>
            <!-- <el-col :span="6">
              <el-select
                v-model="searchForm.priority"
                placeholder="优先级"
                clearable
                style="width: 100%"
              >
                <el-option label="普通" value="normal" />
                <el-option label="紧急" value="urgent" />
                <el-option label="特急" value="super_urgent" />
              </el-select>
            </el-col>
            <el-col :span="6">
              <el-date-picker
                v-model="searchForm.deliveryTime"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                style="width: 100%"
              />
            </el-col> -->
          </el-row>
          <div class="search-actions">
            <el-button type="primary" @click="handleSearch">
              <el-icon><Search /></el-icon>
              搜索
            </el-button>
            <el-button @click="resetSearch">
              <el-icon><Refresh /></el-icon>
              重置
            </el-button>
          </div>
        </div>
      </el-card>
    </div>

    <!-- 任务包列表 -->
    <div class="tasks-section">
      <div class="tasks-header">
        <h3>{{ getTaskTypeTitle() }}</h3>
        <div class="view-toggle">
          <el-button-group>
            <el-button 
              :type="viewMode === 'card' ? 'primary' : ''" 
              @click="viewMode = 'card'"
            >
              <el-icon><Grid /></el-icon>
              卡片视图
            </el-button>
            <el-button 
              :type="viewMode === 'table' ? 'primary' : ''" 
              @click="viewMode = 'table'"
            >
              <el-icon><List /></el-icon>
              表格视图
            </el-button>
          </el-button-group>
        </div>
      </div>

      <!-- 卡片视图 -->
      <div v-if="viewMode === 'card'" class="tasks-grid">
        <div 
          v-for="taskPackage in paginatedTaskPackages" 
          :key="taskPackage.packageId"
          class="task-package-card"
          :class="getTaskCardClass(taskPackage.status)"
        >
          <div class="package-header">
            <div class="package-id">{{ taskPackage.packageId }}</div>
            <div class="package-status">
              <el-tag :type="getStatusType(taskPackage.status)" size="small">
                {{ getStatusText(taskPackage.status) }}
              </el-tag>
            </div>
          </div>
          
          <div class="package-info">
            <div class="info-row">
              <div class="info-item">
                <el-icon><Location /></el-icon>
                <span>{{ taskPackage.deliveryArea }}</span>
              </div>
              <div class="info-item">
                <el-icon><Clock /></el-icon>
                <span>{{ taskPackage.deliveryTime }}</span>
              </div>
            </div>
            
            <div class="package-stats">
              <div class="stat-item">
                <span class="stat-label">订单数</span>
                <span class="stat-value">{{ taskPackage.orderCount }}个</span>
              </div>
              <div class="stat-item">
                <span class="stat-label">配送费</span>
                <span class="stat-value reward">¥{{ taskPackage.totalReward }}</span>
              </div>
              <div class="stat-item">
                <span class="stat-label">预计距离</span>
                <span class="stat-value">{{ taskPackage.estimatedDistance }}公里</span>
              </div>
            </div>
            
            <div class="orders-preview">
              <div class="preview-header">
                <span class="preview-title">包含订单</span>
                <span v-if="taskPackage.orders && taskPackage.orders.length > 0" class="order-count">
                  ({{ taskPackage.orders.length }}个)
                </span>
              </div>
              <div v-if="taskPackage.orders && taskPackage.orders.length > 0" class="order-list">
                <div 
                  v-for="order in taskPackage.orders.slice(0, 3)" 
                  :key="order.orderNumber"
                  class="order-item"
                >
                  <span class="order-number">{{ order.orderNumber }}</span>
                  <span class="customer-name">{{ order.customerName }}</span>
                  <span class="order-address">{{ order.address }}</span>
                </div>
                <div v-if="taskPackage.orders.length > 3" class="more-orders">
                  还有 {{ taskPackage.orders.length - 3 }} 个订单...
                </div>
              </div>
              <div v-else class="order-list-empty">
                <p>点击详情查看具体订单</p>
              </div>
            </div>
          </div>
          
          <div class="package-actions">
            <el-button 
              v-if="taskPackage.status === 0" 
              type="primary" 
              size="small" 
              @click="acceptTaskPackage(taskPackage)"
            >
              <el-icon><Check /></el-icon>
              接单
            </el-button>
            <el-button 
              v-if="taskPackage.status === 1" 
              type="success" 
              size="small" 
              @click="startDelivery(taskPackage)"
            >
              <el-icon><Van /></el-icon>
              开始配送
            </el-button>
            <el-button 
              v-if="taskPackage.status === 1" 
              type="warning" 
              size="small" 
              @click="completeTaskPackage(taskPackage)"
            >
              <el-icon><CircleCheck /></el-icon>
              完成配送
            </el-button>
            <el-button 
              v-if="taskPackage.status === 1" 
              type="danger" 
              size="small" 
              @click="cancelTaskPackage(taskPackage)"
            >
              <el-icon><Close /></el-icon>
              取消
            </el-button>
            <el-button 
              type="info" 
              size="small" 
              @click="viewTaskPackageDetail(taskPackage)"
            >
              <el-icon><View /></el-icon>
              详情
            </el-button>
          </div>
        </div>
      </div>

      <!-- 表格视图 -->
      <div v-else class="tasks-table">
        <el-table :data="paginatedTaskPackages" style="width: 100%" v-loading="loading">
          <el-table-column prop="packageId" label="任务包ID" width="180"></el-table-column>
          <el-table-column prop="deliveryArea" label="配送区域"></el-table-column>
          <el-table-column prop="orderCount" label="订单数量" width="100">
            <template #default="{ row }">
              {{ row.orderCount }}个
            </template>
          </el-table-column>
          <el-table-column prop="totalReward" label="总配送费" width="120">
            <template #default="{ row }">
              ¥{{ row.totalReward }}
            </template>
          </el-table-column>
          <el-table-column prop="estimatedDistance" label="预计距离" width="120">
            <template #default="{ row }">
              {{ row.estimatedDistance }}公里
            </template>
          </el-table-column>
          <el-table-column prop="deliveryTime" label="配送时间" width="180" />
          <el-table-column prop="status" label="状态" width="120">
            <template #default="{ row }">
              <el-tag :type="getStatusType(row.status)" size="small">
                {{ getStatusText(row.status) }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="200" fixed="right">
            <template #default="{ row }">
              <el-button 
                v-if="row.status === 0" 
                type="primary" 
                size="small" 
                @click="acceptTaskPackage(row)"
              >
                接单
              </el-button>
              <el-button 
                v-if="row.status === 1" 
                type="success" 
                size="small" 
                @click="startDelivery(row)"
              >
                开始配送
              </el-button>
              <el-button 
                v-if="row.status === 1" 
                type="warning" 
                size="small" 
                @click="completeTaskPackage(row)"
              >
                完成配送
              </el-button>
              <el-button 
                v-if="row.status === 1" 
                type="danger" 
                size="small" 
                @click="cancelTaskPackage(row)"
              >
                取消
              </el-button>
              <el-button 
                type="info" 
                size="small" 
                @click="viewTaskPackageDetail(row)"
              >
                详情
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <!-- 分页 -->
      <div class="pagination-section">
         <el-pagination
          v-if="total > 0"
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :page-size="pageSize"
          :current-page="currentPage"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[9, 18, 36, 72]"
        >
        </el-pagination>
      </div>
    </div>

    <!-- 任务包详情对话框 -->
    <el-dialog
      v-model="taskPackageDetailVisible"
      title="任务包详情"
      width="800px"
      class="task-package-detail-dialog"
    >
      <div class="task-package-detail">
        <div class="detail-header">
          <div class="detail-number">{{ currentTaskPackage.packageId }}</div>
          <el-tag :type="getStatusType(currentTaskPackage.status)" size="large">
            {{ getStatusText(currentTaskPackage.status) }}
          </el-tag>
        </div>
        
        <el-descriptions :column="2" border>
          <el-descriptions-item label="配送区域">
            {{ currentTaskPackage.deliveryArea }}
          </el-descriptions-item>
          <el-descriptions-item label="配送时间">
            {{ currentTaskPackage.deliveryTime }}
          </el-descriptions-item>
          <el-descriptions-item label="订单数量">
            {{ currentTaskPackage.orderCount }}个
          </el-descriptions-item>
          <el-descriptions-item label="总配送费">
            ¥{{ currentTaskPackage.totalReward }}
          </el-descriptions-item>
          <el-descriptions-item label="预计距离">
            {{ currentTaskPackage.estimatedDistance }}公里
          </el-descriptions-item>
          <el-descriptions-item label="创建时间">
            {{ currentTaskPackage.createdAt }}
          </el-descriptions-item>
        </el-descriptions>
        
        <div class="orders-detail">
          <h4>包含订单详情</h4>
          <el-table :data="currentTaskPackage.orders" style="width: 100%">
            <el-table-column prop="orderNumber" label="订单号" width="180" />
            <el-table-column prop="customerName" label="客户姓名" width="120" />
            <el-table-column prop="customerPhone" label="联系电话" width="140" />
            <el-table-column prop="address" label="配送地址" min-width="200" />
            <el-table-column prop="reward" label="配送费" width="100">
              <template #default="{ row }">
                ¥{{ row.reward }}
              </template>
            </el-table-column>
            <el-table-column prop="status" label="状态" width="100">
              <template #default="{ row }">
                <el-tag :type="getOrderStatusType(row.status)" size="small">
                  {{ getOrderStatusText(row.status) }}
                </el-tag>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  ElButton,
  ElCard,
  ElRow,
  ElCol,
  ElInput,
  ElSelect,
  ElOption,
  ElDatePicker,
  ElButtonGroup,
  ElIcon,
  ElTag,
  ElTable,
  ElTableColumn,
  ElPagination,
  ElDialog,
  ElMessageBox,
  ElMessage,
} from 'element-plus';
import {
  Refresh,
  Search,
  Grid,
  List,
  Location,
  Clock,
  Van,
  CircleCheck,
  Close,
  View,
  Check,
} from '@element-plus/icons-vue';
import {getTaskPackages, acceptTaskPackage, getTaskPackageStats} from '@/assets/delivery.js';

export default {
  name: 'DeliveryTasks',
  components: {
    ElButton, ElCard, ElRow, ElCol, ElInput, ElSelect, ElOption, ElDatePicker,
    ElButtonGroup, ElIcon, ElTag, ElTable, ElTableColumn, ElPagination, ElDialog,
    Refresh, Search, Grid, List, Location, Clock, Van, CircleCheck, Close, View, Check
  },
  data() {
    return {
      loading: false,
      taskType: 'pending', // 'pending', 'delivering', 'completed', 'cancelled'
      stats: {
        pending: 0,
        delivering: 0,
        completed: 0,
        cancelled: 0,
      },
      searchForm: {
        packageId: '',
        deliveryArea: '',
        priority: '',
        deliveryTime: null,
      },
      viewMode: 'card', // 'card' or 'table'
      taskPackages: [],
      currentPage: 1,
      pageSize: 9,
      total: 0, // 新增 total，用于存储总记录数
      dialogVisible: false,
      selectedPackage: null,
    };
  },
  computed: {
    paginatedTaskPackages() {
      const start = (this.currentPage - 1) * this.pageSize;
      const end = start + this.pageSize;
      return this.taskPackages.slice(start, end);
    },
  },
  created() {
    this.fetchTaskPackages();
    this.fetchTaskStats();
  },
  methods: {
    // 数据获取
    async fetchTaskPackages() {
      this.loading = true;
      
      const queryPage = {
          page: this.currentPage,
          size: this.pageSize,
          status: this.taskType,
          packageId: this.searchForm.packageId,
          deliveryArea: this.searchForm.deliveryArea,
          priority: this.searchForm.priority,
      }
      
      try {
        const response = await getTaskPackages(queryPage);
        console.log(response.data.data);
        
        if (response.data && response.data.data) {
            this.taskPackages = response.data.data.records || [];
            this.total = response.data.data.total || 0;
        } else {
            this.taskPackages = [];
            this.total = 0;
        }
      } catch (error) {
        console.error('获取任务包列表失败:', error);
        ElMessage.error('获取任务包列表失败');
        this.taskPackages = [];
        this.total = 0;
      } finally {
        this.loading = false;
      }
    },
    async fetchTaskStats() {
      try {
        const response = await getTaskPackageStats();
        // 【调试日志】打印从后端接收到的原始数据
        console.log('【统计数据接口返回】:', response.data);
        // 根据您封装的返回结构，从 res.data.data 中获取数据
        if (response.data && response.data.data) {
          this.stats = response.data.data;
          // 计算总数
          this.stats.sum = 
            (this.stats.pending || 0) +
            (this.stats.delivering || 0) +
            (this.stats.completed || 0) +
            (this.stats.cancelled || 0);
        }
      } catch (error) {
        console.error('获取统计数据失败:', error);
      }
    },

    // 页面交互
    handleRefresh() {
      this.fetchTaskStats();
      this.fetchTaskPackages();
      ElMessage.success('数据已刷新');
    },
    switchTaskType(type) {
      this.taskType = type;
      this.currentPage = 1;
      this.fetchTaskPackages();
    },
    handleSearch() {
      this.currentPage = 1;
      this.fetchTaskPackages();
    },
    resetSearch() {
      this.searchForm = {
        packageId: '',
        deliveryArea: '',
        priority: '',
        deliveryTime: null,
      };
      this.handleSearch();
    },

    // 任务包操作
    async acceptTaskPackage(taskPackage) {
      try {
        await ElMessageBox.confirm(`确认接收任务包 ${taskPackage.packageId} 吗？`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'info',
        });
        await acceptTaskPackage(taskPackage.packageId);
        ElMessage.success('接单成功');
        this.handleRefresh();
      } catch (e) {
        if (e !== 'cancel') {
          ElMessage.error('接单失败');
        }
      }
    },
    async startDelivery(taskPackage) {
      await updateTaskPackageStatus(taskPackage.packageId, 'delivering');
      ElMessage.success('操作成功，已开始配送');
      this.handleRefresh();
    },
    async completeTaskPackage(taskPackage) {
      await updateTaskPackageStatus(taskPackage.packageId, 'completed');
      ElMessage.success('操作成功，任务包已完成');
      this.handleRefresh();
    },
    async cancelTaskPackage(taskPackage) {
      await updateTaskPackageStatus(taskPackage.packageId, 'pending');
      ElMessage.success('操作成功，任务包已取消配送');
      this.handleRefresh();
    },
    viewTaskPackageDetail(taskPackage) {
      this.$router.push(`/delivery/tasks/${taskPackage.packageId}`);
    },

    // 分页
    handleSizeChange(val) {
      this.pageSize = val;
      this.currentPage = 1; // 修改每页数量时，回到第一页
      this.fetchTaskPackages(); // 重新请求数据
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.fetchTaskPackages(); // 页码改变，重新请求数据
    },
    
    // UI 辅助方法
    getTaskTypeTitle() {
      const titles = {
        pending: '待接单任务包',
        delivering: '配送中任务包',
        completed: '已完成任务包',
        cancelled: '已取消任务包',
      };
      return titles[this.taskType] || '全部任务包';
    },
    getStatusText(status) {
      return { 0: '待接单', 1: '配送中', 2: '已完成', 3: '已取消' }[status] || '未知';
    },
    getStatusType(status) {
      return { 0: 'info', 1: 'warning', 2: 'success', 3: 'danger' }[status] || 'info';
    },
    getTaskCardClass(status) {
      return { 0: 'pending', 1: 'delivering', 2: 'completed', 3: 'cancelled' }[status] || '';
    },
    getOrderStatusText(status) {
      return { 0: '待配送', 1: '配送中', 2: '已签收', 3: '异常' }[status] || '未知';
    },
    getOrderStatusType(status) {
      return { 0: 'info', 1: 'warning', 2: 'success', 3: 'danger' }[status] || 'info';
    },
    tableRowClassName({ row }) {
      if (this.getStatusText(row.status) === '已完成') return 'success-row';
      return '';
    },
    showDetailDialog(taskPackage) {
      this.selectedPackage = taskPackage;
      this.dialogVisible = true;
    },
  }
};
</script>

<style scoped>
.delivery-tasks {
  padding: 24px;
  background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
  min-height: 100vh;
}

/* 页面标题 */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.page-title {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  color: #1f2937;
}

.page-desc {
  margin: 0;
  color: #6b7280;
  font-size: 14px;
}

.header-right {
  display: flex;
  gap: 12px;
}

/* 任务统计 */
.task-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-item {
  background: white;
  border-radius: 16px;
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
  border: 2px solid transparent;
}

.stat-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.stat-item.active {
  border-color: #10b981;
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: white;
}

.stat-icon.pending {
  background: linear-gradient(135deg, #3b82f6, #60a5fa);
}

.stat-icon.delivering {
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
}

.stat-icon.completed {
  background: linear-gradient(135deg, #10b981, #34d399);
}

.stat-icon.cancelled {
  background: linear-gradient(135deg, #ef4444, #f87171);
}

.stat-icon.sum {
  background: linear-gradient(135deg, #6366f1, #a5b4fc);
}

.stat-content {
  flex: 1;
}

.stat-number {
  font-size: 24px;
  font-weight: 700;
  color: #1f2937;
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: #6b7280;
  margin-top: 4px;
}

.stat-item.sum {
  background: linear-gradient(135deg, #6366f1, #a5b4fc);
  color: #fff;
}

.stat-icon.sum {
  background: linear-gradient(135deg, #6366f1, #a5b4fc);
}

/* 搜索区域 */
.search-section {
  margin-bottom: 24px;
}

.search-card {
  border: none;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.search-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* 任务区域 */
.tasks-section {
  background: white;
  border-radius: 16px;
  padding: 24px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

.tasks-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.tasks-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #1f2937;
}

/* 卡片视图 */
.tasks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.task-package-card {
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 20px;
  transition: all 0.3s ease;
  background: white;
}

.task-package-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.task-package-card.pending {
  border-left: 4px solid #3b82f6;
}

.task-package-card.delivering {
  border-left: 4px solid #f59e0b;
}

.task-package-card.completed {
  border-left: 4px solid #10b981;
}

.task-package-card.cancelled {
  border-left: 4px solid #ef4444;
}

.package-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.package-id {
  font-size: 16px;
  font-weight: 600;
  color: #1f2937;
}

.package-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.info-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #6b7280;
}

.package-stats {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px;
  background: #f8fafc;
  border-radius: 8px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label {
  font-size: 12px;
  color: #6b7280;
}

.stat-value {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
}

.stat-value.reward {
  color: #10b981;
}

.orders-preview {
  margin-top: 16px;
  padding: 12px;
  background: #f1f5f9;
  border-radius: 8px;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.preview-title {
  font-size: 14px;
  font-weight: 600;
  color: #1f2937;
}

.order-count {
  font-size: 12px;
  color: #6b7280;
}

.order-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.order-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  background: white;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
}

.order-number {
  font-size: 12px;
  font-weight: 600;
  color: #1f2937;
  min-width: 120px;
}

.customer-name {
  font-size: 12px;
  color: #6b7280;
  min-width: 80px;
}

.order-address {
  font-size: 12px;
  color: #6b7280;
  flex: 1;
  text-align: right;
}

.more-orders {
  font-size: 12px;
  color: #6b7280;
  text-align: center;
  padding: 8px;
  background: #f8fafc;
  border-radius: 6px;
}

.package-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

/* 表格视图 */
.tasks-table {
  margin-bottom: 24px;
}

/* 分页 */
.pagination-section {
  display: flex;
  justify-content: center;
  padding-top: 24px;
  border-top: 1px solid #e5e7eb;
}

/* 任务包详情对话框 */
.task-package-detail-dialog :deep(.el-dialog) {
  border-radius: 16px;
}

.task-package-detail {
  padding: 20px 0;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #e5e7eb;
}

.detail-number {
  font-size: 20px;
  font-weight: 600;
  color: #1f2937;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .delivery-tasks {
    padding: 16px;
  }
  
  .task-stats {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .tasks-grid {
    grid-template-columns: 1fr;
  }
  
  .page-header {
    flex-direction: column;
    gap: 16px;
  }
  
  .tasks-header {
    flex-direction: column;
    gap: 16px;
    align-items: flex-start;
  }
}
</style> 